home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / BOFH / HQPreferencesController.m < prev    next >
Encoding:
Text File  |  2001-06-23  |  1.9 KB  |  69 lines

  1. // HQPreferencesController.m
  2. //
  3. // You may freely copy, distribute, and reuse the code in this example.
  4. // Apple disclaims any warranty of any kind, expressed or  implied, as to its
  5. // fitness for any particular use.
  6.  
  7. #import "HQPreferencesController.h"
  8.  
  9. #ifdef ENABLE_PREFERENCES
  10.  
  11. NSString *HQPreferencesDidChangeNotification = @"HQPreferencesDidChange";
  12.  
  13. @implementation HQPreferencesController
  14.  
  15. + (id)sharedPreferencesController {
  16.     static HQPreferencesController *sharedInstance = nil;
  17.     if (!sharedInstance) {
  18.         sharedInstance = [[HQPreferencesController alloc] init];
  19.     }
  20.     return sharedInstance;
  21. }
  22.  
  23. - (id)init {
  24.     self = [super initWithWindowNibName:@"HQPreferences" owner:self];
  25.     if (self) {
  26.         [self setWindowFrameAutosaveName:@"HQPreferences"];
  27.         [self readDefaults];
  28.     }
  29.     return self;
  30. }
  31.  
  32. - (void)dealloc {
  33.     [[NSNotificationCenter defaultCenter] removeObserver:self];
  34.  
  35.     [super dealloc];
  36. }
  37.  
  38. - (void)readDefaults {
  39.     // FILL THIS IN: Read from user defaults if you cache values
  40. }
  41.  
  42. - (void)revertPanel {    
  43.     // FILL THIS IN: Update the preferences UI to reflect the current pref settings.
  44. }
  45.  
  46. - (void)windowDidLoad {
  47.     [super windowDidLoad];
  48.     [self revertPanel];
  49. }
  50.  
  51. - (void)didChange {
  52.     // CALL THIS:  Call this method any time the value of a preference is changed from the panel in addition to actually setting the value in NSUserDefaults and in any local cache.
  53.     [[NSNotificationCenter defaultCenter] postNotificationName:HQPreferencesDidChangeNotification object:self];
  54. }
  55.  
  56. - (void)windowWillClose:(NSNotification *)aNotification {
  57.     // Try and make sure to catch edits when the user closes the window.
  58.     [[self window] makeFirstResponder:[self window]];
  59. }
  60.  
  61. - (void)windowDidResignKey:(NSNotification *)aNotification {
  62.     // Try and make sure to catch edits when the user activates another window.
  63.     [[self window] makeFirstResponder:[self window]];
  64. }
  65.  
  66. @end
  67.  
  68. #endif
  69.